<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 有序数组中差绝对值之和 -->
    <script>
      var getSumAbsoluteDifferences = function (nums) {
        let n = nums.length,
          ans = Array(n),
          f = 0
        for (let i = 0; i < n; i++) {
          ans[0] = f += nums[i] - nums[0]
        }
        for (let i = 1; i < n; i++) {
          ans[i] = f += (2 * i - n) * (nums[i] - nums[i - 1])
        }
        return ans
      }
      console.log(getSumAbsoluteDifferences([2, 3, 5]))
    </script>
  </body>
</html>
